var TechnologyConsumable = {
    id: "TechnologyConsumableTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

TechnologyConsumable.initColumn = function () {// 初始化表格的列
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: 'customerId', field: 'customerId', visible: false, align: 'center', valign: 'middle'},
        {title: '病历号', field: 'medicalRecordNumber', align: 'center', valign: 'middle', width: 130},
        {title: '患者姓名', field: 'customerName', align: 'center', valign: 'middle', width: 110},
        {title: '电话', field: 'customerPhone', align: 'center', valign: 'middle',  width: 140},
        {title: '性别', field: 'sex', align: 'center', valign: 'middle', width: 80},
        {title: '年龄', field: 'customerAge', align: 'center', valign: 'middle', width: 80},
        {title: '左上', field: 'leftUp', visible: false, align: 'center', valign: 'middle'},
        {title: '右上', field: 'rightUp', visible: false, align: 'center', valign: 'middle'},
        {title: '左下', field: 'leftDown', visible: false, align: 'center', valign: 'middle'},
        {title: '右下', field: 'rightDown', visible: false, align: 'center', valign: 'middle'},
        {title: '耗材名称', field: 'consumableName', align: 'center', valign: 'middle', width: 110},
        {title: '金额', field: 'amount', align: 'center', valign: 'middle', width: 110},
        {title: '数量', field: 'number', align: 'center', valign: 'middle', width: 80},
        {title: '所属类型', field: 'type', align: 'center', valign: 'middle', width: 110},
        {title: '创建时间', field: 'createTime', align: 'center', valign: 'middle', width: 170,
            formatter: function (value, row, index) {
                return value.substring(0, 19);
            }
        },
        {title: '医生', field: 'doctor', align: 'center', valign: 'middle', width: 100},
        {title: '门诊', field: 'arrivalStore', align: 'center', valign: 'middle', width: 100},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', width: 120,
            formatter: function (value, row, index) {
                return "<span title='"+value+"'>" + value + "</span>"
            },
            cellStyle: function (value, row, index) {
                return {css: {"overflow":"hidden","white-space":"nowrap","text-overflow":"ellipsis"}}
            }
        },
    ];
    return columns;
};
var date = new Date();
var currentYear = date.getFullYear();       // 当前年份
var currentMonth = date.getMonth() + 1;    // 当前月份
var currentDay = date.getDate();         // 今日日期 几号
if (currentMonth < 10) currentMonth = "0" + currentMonth;
if (currentDay < 10) currentDay = "0" + currentDay;

TechnologyConsumable.search = function () {// 查询预约客户列表
    TechnologyConsumable.table.refresh({query: TechnologyConsumable.formParams()});
};

TechnologyConsumable.resetSearch = function () {
    $("#doctorInputPublic",parent.document).val("");
    $("#startTime").val("");
    $("#endTime").val("");
    $("#arrivalStore").selectpicker('deselectAll');
    TechnologyConsumable.search()
};

var parseParam = function (param) {//把对象拼接成URL的键值对参数param1=value1&param2=value2
    var paramStr = "";
    $.each(param, function (i) {
        paramStr += '&' + getSingleData(param, i);
    });
    return paramStr.substr(1);
};

var getSingleData = function (param, key) {
    return key + "=" + param[key];
};

TechnologyConsumable.technologyConsumableExport = function () {//导出
    var param = parseParam(TechnologyConsumable.formParams());
    location.href = Feng.ctxPath + '/technologyConsumable/technologyConsumableExport?' + param;
};

TechnologyConsumable.close = function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
};

TechnologyConsumable.formParams = function () {// 查询表单提交参数对象
    var queryData = {};
    queryData['reach'] = $("#doctorInputPublic",parent.document).val();
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    var valuearrivalStore = $("#arrivalStore").val();
    var strarrivalStore = "";
    if (valuearrivalStore != null && valuearrivalStore != "") {
        for (var i = 0; i < valuearrivalStore.length; i++) {
            if (i == (valuearrivalStore.length - 1)) {
                strarrivalStore += valuearrivalStore[i];
            } else {
                strarrivalStore += valuearrivalStore[i] + ",";
            }
        }
    }
    queryData['arrivalStore'] = strarrivalStore;  //门诊
    return queryData;
};

$("#doctorSearchAll", parent.document).click(function () {//主页搜索
    TechnologyConsumable.search();
});

$(function () {
    document.getElementById("startTime").value = currentYear + "-" + currentMonth + "-" + currentDay + " " + "00:00:00";
    document.getElementById("endTime").value = currentYear + "-" + currentMonth + "-" + currentDay + " " + "23:59:59";
    var defaultColunms = TechnologyConsumable.initColumn();
    var table = new BSTable(TechnologyConsumable.id, "/technologyConsumable/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(TechnologyConsumable.formParams());
    TechnologyConsumable.table = table.init();
    TechnologyConsumable.search();
    $(document).on('click','#laydate_clear,#laydate_today,#laydate_ok',function () {TechnologyConsumable.search();});
    checkDate = function () {TechnologyConsumable.search();};
});